﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;

using Winsteps.Validator;

public partial class Manage_roleManage : System.Web.UI.Page
{
    BLL.RoleBll roleBll = new BLL.RoleBll();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadValidator();

            BindData();
        }
    }

    private void BindData()
    {
        DataTable table = roleBll.GetAllRole();
        RoleList.DataSource = table;
        RoleList.DataBind();
    }
    protected void RoleList_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Label1.Text = RoleList.Rows[RoleList.SelectedIndex].Cells[1].Text.ToString();
        div_Add.Style["display"] = "none";
        Label1.Text = ((Label)RoleList.Rows[RoleList.SelectedIndex].FindControl("lb_RoleId")).Text.ToString();
        lb_SelectedRole.Text = RoleList.Rows[RoleList.SelectedIndex].Cells[1].Text.ToString();
        btn_Del.Enabled = true;
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        RoleList.SelectedIndex = -1;
        lb_SelectedRole.Text = "选择相应的角色";
        btn_Del.Enabled = false;
        div_Add.Style["display"] = "block";
    }
    protected void btn_Del_Click(object sender, EventArgs e)
    {
        int roleId = int.Parse(Label1.Text.ToString());
        if (roleBll.DeleteRole(roleId))
        {
            lb_SelectedRole.Text = "选择相应的角色";
            RoleList.SelectedIndex = -1;
        }
        btn_Del.Enabled = false;

        BindData();
        
    }
    protected void btn_AddRole_Click(object sender, EventArgs e)
    {
        string name = txt_roleName.Text.ToString();
        roleBll.AddRole(name);
        div_Add.Style["display"] = "none";
        BindData();
    }

    private void LoadValidator()
    {
        
    }
}
